<html>
  <head>
    <title>加载中,请稍等...</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1">
    <meta name="description" content="点击链接前往微信打开微信小程序~" />
    <script>
      window.onerror = e => {
        console.error(e)
      }
    </script>
    <!-- weui 样式 -->
    <link rel="stylesheet" href="https://res.wx.qq.com/open/libs/weui/2.4.0/weui.min.css"></link>
    <script src="https://nilife.oss-cn-beijing.aliyuncs.com/miniapp/images/setting/jquery-3.5.1-min.js"></script>
    <script src="https://wailiancn.oss-cn-beijing.aliyuncs.com/assets/js/v2/qrcode.min.js?versionId=CAEQIRiBgICI8_PA_RciIDE1ZmZiMmM2NmIyODRmMDE4Mzg0NWM5YTY5OTE5MDI0"></script>
    <script src="https://wailiancn.oss-cn-beijing.aliyuncs.com/assets/js/bsion/bsion.js?versionId=CAEQFBiBgICK3qOI0hciIGMxMGEzODMxZDM4OTRlNzFiOTJiMzBiZGZiOThkMjEy"></script>
    <link rel="stylesheet" type="text/css" href="https://ttwls.oss-cn-beijing.aliyuncs.com/v/v3/home_links.min.css?v=2022062401">
  </head>
  <body>
    <div class="page full">
        <div id="public-web-container" class="public-container">
            <div id="safe-notice" style="display:none;">
                <div class="safe-notice">
                    <img src="https://nilife.oss-cn-beijing.aliyuncs.com/miniapp/images/setting/safe.png">
                    <p>本链接经过<font style="font-weight: 500;color: #333333;">SSL安全加密</font>,请放心点击!</p>
                </div>
            </div>
            <div id="style_normal" style="display:none;">
                <img class="logo" src="">
                <p class="notice-msg"><small>正在跳转到微信...</small><br>如未自动打开微信请点击下方按钮</p>
                <div class="button-container">
                    <a id="public-web-jump-button" href="" class="default" style="">
                        <span id="public-web-jump-button-loading" class="weui-primary-loading weui-primary-loading_transparent">
                            <i class="weui-primary-loading__dot"></i>
                        </span>
                        正在打开微信
                    </a>
                </div>
                <a id="dianjiimg_links" href="">
                </a>
                <div class="qrcodes-container" id="qrcodes"></div>
            </div>
            <div id="style_full" style="display:none;">
                <a id="dianjiimg_links_full" href="">
                    <img class="fullimg" src="">
                </a>
                <div id="button_container_full" class="button-container-none">
                    <a id="public-web-jump-button-full" href="" style="">
                    </a>
                </div>
            </div>
        </div>
    </div>

    <script type="text/javascript">
        $(document).ready(function(){
            getLinksDetial();
        });

        function getLinksDetial() {
            var weixin = isWeiXin();
            $.ajax({
                url:"https://bab.moreqifu.cn/web/links/{{ $links_id }}",
                data:{
                    "sign": "{{ $sign }}",
                    "token": "{{ isset($token) ? $token : '' }}"
                },
                success:function(result){
                    if (result.status == "success") {
                        // 复制搜索模式
                        if(result.links.platfrom_type == 7) {
                            window.location.href = "{{ config('spare_urls.spareurl') }}/copy/{{ $links_id }}";
                        // 朋友圈分享陌生
                        } else if(result.links.platfrom_type == 10) {
                            window.location.href = "{{ config('spare_urls.spareurl') }}/share/{{ $links_id }}";
                        } else {
                            var styles = JSON.parse(result.links.styles);
                            //一键审核跳转
                            if(styles.style == 4){
                                window.location.href = styles.redirect_url;
                                return;
                            }
                            // 修改Header内的参数
                            $("title").html(result.links.title);
                            if(styles.redirect_style == 1){
                                // 微信内不打开urlscheme
                                if (!weixin) {
                                    window.location.href = result.links.urlscheme;
                                }
                            }
                            $("head").append('<meta itemprop="name" content="'+result.links.title+'"/>');
                            $("head").append('<meta itemprop="image" content="'+result.links.logo+'"/>');
                            $("head").append('<link href="'+result.links.logo+'" rel="apple-touch-icon-precomposed">');
                            $("head").append('<link href="'+result.links.logo+'" sizes="114x114" rel="apple-touch-icon-precomposed">');
                            if (styles.style == 1 || styles.style == 2) {
                                $("#safe-notice").show();
                                $("#style_normal").show();
                                $("#style_full").hide();
                                if (styles.style == 2) {
                                    $(".logo").attr("src",styles.logo);
                                } else {
                                    $(".logo").attr("src","https://nilife.oss-cn-beijing.aliyuncs.com/wepage/20210421-180054-178.png");
                                }
                                if (styles.gif_show != 3) {
                                    $("#dianjiimg_links").attr('href',result.links.urlscheme).html('<img id="dianjiimg" class="dianji-img" src="https://nilife.oss-cn-beijing.aliyuncs.com/miniapp/banners/dianji.gif">');
                                }
                                var button_border = (styles.button_border == 1) ? '3px':'50px';
                                $("#public-web-jump-button").attr("href",result.links.urlscheme).css({"background-color":styles.button_background_color,"color":styles.button_text_color,"border-radius":button_border});
                            }else if(styles.style == 4){
                                window.location.href = styles.redirect_url;
                            }else {
                                $("#safe-notice").hide();
                                $("#style_normal").hide();
                                $("#style_full").show();
                                if (styles.postion == 3) {
                                    var postion_class = "button-container-bottom";
                                } else if(styles.postion == 2) {
                                    var postion_class = "button-container-top";
                                } else {
                                    var postion_class = "button-container-none";
                                }
                                $("#dianjiimg_links_full").attr('href',result.links.urlscheme);
                                $(".fullimg").attr('src',styles.logo);
                                $("#button_container_full").attr("class",postion_class);
                                $("#public-web-jump-button-full").attr("href",result.links.urlscheme).css({"background-color":styles.button_background_color,"color":styles.button_text_color});
                                if (result.links.redirect_style == 1) {
                                    $("#public-web-jump-button-full").html('<span id="public-web-jump-button-loading" class="weui-primary-loading weui-primary-loading_transparent"><i class="weui-primary-loading__dot"></i></span>正在打开微信');
                                } else {
                                    $("#public-web-jump-button-full").html(styles.botton_text);
                                }
                            }
                            jsUpdate(result,styles);
                        }

                        if (result.links.type == 2) {
                            usersStatistics();
                        }
                    } else {
                        $(".public-container").html('<img class="error-images" src="https://nilife.oss-cn-beijing.aliyuncs.com/miniapp/images/setting/error.png"><p class="error-msg">'+result.msg+'</p>');
                    }
                }
            });
        }

        function jsUpdate(result,styles) {
            var mobile_flag = isMobile();
            var weixin = isWeiXin();
            if(mobile_flag){
                var baidu = isBaidu();
                var uc = isUc();
                var weibo = isWeibo();
                var douyin = isDouyin();
                if (weixin) {
                    if ($.inArray(result.links.platfrom_type, [2,3,4,5,6]) >= 0) {
                        // window.location.href = result.links.urlscheme;
                        window.location.href = "{{ config('spare_urls.spareurl') }}/openminiapp/{{ $links_id }}";
                    } else if($.inArray(result.links.platfrom_type, [8,9,11,12]) >= 0) {
                        window.location.href = "{{ config('spare_urls.spareurl') }}/article/{{ $links_id }}";
                    } else if(result.links.platfrom_type == 1) {
                        window.location.href = result.links.msg;
                    } else {
                        // 7和10不会到此界面
                        if (styles.redirect_style == 1) {
                            window.location.href = result.links.msg;
                        }
                    }
                } else if (uc) {
                    $("#public-web-jump-button").html(styles.botton_text);
                    $("#dianjiimg").show();
                } else if (weibo) {
                    var urlpath = getQueryVariable("path");
                    var path = (urlpath == false) ? encodeURIComponent(result.links.path) : urlpath;
                    if (path == "") {
                        $(".notice-msg").html("小程序路径不存在,无法实现跳转！");
                    } else {
                        $(".notice-msg").html("正在跳转微信小程序,如未自动打开微信请点击下方按钮！");
                    }
                    $("#public-web-jump-button").attr("href","sinaweibo://wbdiversion?username="+result.links.original_id+"&path="+path);
                    $("#dianjiimg_links_full").attr("href","sinaweibo://wbdiversion?username="+result.links.original_id+"&path="+path);
                    $("#public-web-jump-button-full").attr("href","sinaweibo://wbdiversion?username="+result.links.original_id+"&path="+path);
                    if (styles.redirect_style == 1) {
                        window.location.href="sinaweibo://wbdiversion?username="+result.links.original_id+"&path="+path;
                    }
                    setTimeout(function (){
                        $("#public-web-jump-button").html(styles.botton_text);
                        $("#dianjiimg").show();
                    }, 3000);
                } else if (douyin) {
                    window.location.href = result.links.urlscheme;
                    if (styles.style != 3) {
                        $("#public-web-jump-button span").click();
                    } else {
                        $("#button_container_full a").click();
                    }
                } else {
                    if (styles.gif_show == 2) {
                        $("#dianjiimg").show();
                    }
                    if (styles.redirect_style == 1) {
                        window.location.href = result.links.urlscheme;
                        if (styles.style != 3) {
                            $("#public-web-jump-button span").click();
                        } else {
                            $("#button_container_full a").click();
                        }
                    }
                    setTimeout(function (){
                        $("#public-web-jump-button").html(styles.botton_text);
                        $("#dianjiimg").show();
                    }, 3000);
                }
            } else {
                // 强行调用一波URLScheme
                window.location.href = result.links.urlscheme;
                if ($.inArray(result.links.platfrom_type, [2,3,4,5,6,7,10]) >= 0) {
                    $(".notice-msg").html("请扫描下方二维码,使用手机访问本网页！");
                    showQrcode();
                    $("#public-web-jump-button").css({"background-color":"#CCCCCC","color":"#333333"}).html("扫码下方二维码");
                } else if($.inArray(result.links.platfrom_type, [8,9,11,12]) >= 0) {
                    window.location.href = "{{ config('spare_urls.spareurl') }}/article/{{ $links_id }}";
                } else {
                    window.location.href = result.links.msg;
                }
            }
        }

        function showQrcode() {
            $("#qrcodes").hide().html("");
            var qrcode = new QRCode(document.getElementById("qrcodes"), {
                text: window.location.href,
                width: 150,
                height: 150,
                colorDark : "#000000",
                colorLight : "#ffffff",
                correctLevel : QRCode.CorrectLevel.H
            });
            $("#qrcodes").show();
        }

        //判断是否是微信浏览器的函数
        function isWeiXin(){
            var ua = navigator.userAgent.toLowerCase()
            var isWXWork = ua.match(/wxwork/i) == 'wxwork'
            var isWeixin = !isWXWork && ua.match(/micromessenger/i) == 'micromessenger'
            return isWeixin;
        }

        //判断是否是抖音
        function isDouyin(){
            ua = navigator.userAgent.toLowerCase();
            if (ua.indexOf('aweme') >-1){
                return true;
            } else {
                return false;
            }
        }

        //判断是否是百度浏览器浏览器的函数,百度不能调起其他APP
        function isBaidu(){
            ua = navigator.userAgent.toLowerCase();
            if (ua.indexOf('baiduboxapp/') >-1){
                return true;
            } else {
                return false;
            }
        }

        function isUc() {
            if (navigator.userAgent.match(/(UCBrowser|Quark)/i)) {
                return true;
            } else {
                return false;
            }
        }

        function isWeibo() {
            var ua = navigator.userAgent;
            if(ua.indexOf('Weibo') > -1) {
                return true;
            } else {
                return false;
            }
        }

        function getQueryVariable(variable)
        {
            var query = window.location.search.substring(1);
            var vars = query.split("&");
            for (var i=0;i<vars.length;i++) {
                var pair = vars[i].split("=");
                if(pair[0] == variable){return pair[1];}
            }
            return(false);
        }

        function isMobile() {
            var mobile_flag = true;
            if (navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|XiaoMi|IEMobile)/i)) {
                mobile_flag = true;
            } else {
                mobile_flag = false;
            }
            var screen_width = window.screen.availWidth;
            // var screen_height = window.screen.height;

            //根据屏幕分辨率判断是否是手机
            if(screen_width < 700){
                mobile_flag = true;
            }
            return mobile_flag;
        }

        function isIphone() {
            if (navigator.userAgent.match(/(iPhone|iPod|ios|iPad)/i)) {
                return true;
            } else {
                return false;
            }
        }

        function usersStatistics() {
            var usersview = localStorage.getItem("usersview{{ $links_id }}");
            if (!usersview && typeof(usersview)!="undefined" && usersview!=0){
                var bsions = new Bsion("https://bab.moreqifu.cn/api/version/1/links/links_ip_statistics",{"links_id":"{{ $links_id }}","sorts":"1"},true,false);  
                bsions.device();
                localStorage.setItem("usersview{{ $links_id }}","{{ $links_id }}");
            } else {
                console.log("{{ $links_id }}重复用户！");
            }
        }
    </script>
  </body>
</html>